/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CompModDesktop.java
 *
 * Created on Jan 18, 2010, 9:03:07 PM
 */

package org.femto.compmod.gui;
import java.io.IOException;
import java.sql.SQLException;
import org.femto.compmod.OptionsDatabase;

/**
 *
 * @author root
 */
public class CompModDesktop extends javax.swing.JFrame {

    /** Creates new form CompModDesktop */
    public CompModDesktop() throws IllegalArgumentException, SQLException, IOException {
        initComponents();
        setTitle("COMPMOD/FEMTO");
        loadOptions();
        horizontalSplitPane.setRightComponent(new Console());
    }

    private void loadOptions() throws SQLException {
        OptionsDatabase.loadFrameBounds("desktop", this);
        verticalSplitPane.setDividerLocation(OptionsDatabase.loadOptionInt("gui.desktop.verticalSplitLocation"));
        horizontalSplitPane.setDividerLocation(OptionsDatabase.loadOptionInt("gui.desktop.horizontalSplitLocation"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        horizontalSplitPane = new javax.swing.JSplitPane();
        verticalSplitPane = new javax.swing.JSplitPane();
        desktopPane = new javax.swing.JDesktopPane();
        TabsPane = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        exitMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        horizontalSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        verticalSplitPane.setDividerLocation(300);
        verticalSplitPane.setDividerSize(8);
        verticalSplitPane.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        verticalSplitPane.setMinimumSize(new java.awt.Dimension(1, 1));

        desktopPane.setBackground(new java.awt.Color(204, 204, 204));
        desktopPane.setDragMode(javax.swing.JDesktopPane.OUTLINE_DRAG_MODE);
        verticalSplitPane.setRightComponent(desktopPane);

        TabsPane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        TabsPane.setMinimumSize(new java.awt.Dimension(0, 0));
        TabsPane.setName(""); // NOI18N

        jTree1.setShowsRootHandles(true);
        jScrollPane1.setViewportView(jTree1);

        TabsPane.addTab("Models", jScrollPane1);
        TabsPane.addTab("Materials", jTabbedPane1);

        verticalSplitPane.setLeftComponent(TabsPane);
        TabsPane.getAccessibleContext().setAccessibleName("Models");

        horizontalSplitPane.setLeftComponent(verticalSplitPane);

        fileMenu.setText("System");

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(horizontalSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 558, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(horizontalSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void storeOptions() throws SQLException {
            OptionsDatabase.storeFrameBounds("desktop", this);
            OptionsDatabase.storeOptionInt("gui.desktop.verticalSplitLocation", verticalSplitPane.getDividerLocation());
            OptionsDatabase.storeOptionInt("gui.desktop.horizontalSplitLocation", horizontalSplitPane.getDividerLocation());
    }

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        try {
            storeOptions();
        }
        catch(Exception e) {
            System.out.println(e.toString());
        }
        finally {
            System.exit(0);
        }
    }//GEN-LAST:event_exitMenuItemActionPerformed

    public javax.swing.JDesktopPane getDeskPane() {
        return desktopPane;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane TabsPane;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JSplitPane horizontalSplitPane;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTree jTree1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JSplitPane verticalSplitPane;
    // End of variables declaration//GEN-END:variables

}
